﻿using B.S.BaseData.Api.Read.Command.GoodsCommand;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interface;
using B.S.BataBase.Domain.Entitys;
using MediatR;
using System.Collections.Generic;

namespace B.S.BaseData.Api.Read.CommandHandler.GoodsCommandHandler
{
    public class GoodscultivationShowCommandHandler : IRequestHandler<GoodscultivationShowCommand, APIResult<GoodscultivationInfo>>
    {
        private readonly IBaseRepository<GoodscultivationInfo> _cultivationrepository;
        public GoodscultivationShowCommandHandler(IBaseRepository<GoodscultivationInfo> cultivationrepository)
        {
            _cultivationrepository=cultivationrepository;
        }
        public async Task<APIResult<GoodscultivationInfo>> Handle(GoodscultivationShowCommand request, CancellationToken cancellationToken)
        {
            APIResult<GoodscultivationInfo> result=new APIResult<GoodscultivationInfo>();
            try
            {
                var list = await _cultivationrepository.GetValues(x=>x.GoodsId==request.GoodsId);
                result.Data = list;
                result.Msg = "养殖列表显示成功";
                result.Code=ApiEnum.Success;
                return await Task.FromResult(result);
            }
            catch (Exception)
            {
                result.Msg = "养殖列表显示失败";
                result.Code = ApiEnum.Fail;
                return await Task.FromResult(result);
            }
        }
    }
}
